package com.yanqu.road.dao.impl.activity.xiuxian.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.xiuxian.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class XiuXianConfigDaoImpl extends TempDao {

    private static String getXiuXianPvpPlaceConfigSql = "select * from `t_s_activity_xiuxian_pvp_place` where `activityId`=?";

    public Map<Integer, XiuXianPvpPlaceConfig> getXiuXianPvpPlaceConfigMap(int activityId) {
        Map<Integer, XiuXianPvpPlaceConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianPvpPlaceConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianPvpPlaceConfig xiuXianPvpPlaceConfig = new XiuXianPvpPlaceConfig();
                xiuXianPvpPlaceConfig.setActivityId(rs.getInt("activityId"));
                xiuXianPvpPlaceConfig.setId(rs.getInt("id"));
                xiuXianPvpPlaceConfig.setType(rs.getInt("type"));
                xiuXianPvpPlaceConfig.setName(rs.getString("name"));
                xiuXianPvpPlaceConfig.setLevel(rs.getInt("level"));
                xiuXianPvpPlaceConfig.setRadius(rs.getInt("radius"));
                xiuXianPvpPlaceConfig.setSeizeScore(rs.getInt("seizeScore"));
                xiuXianPvpPlaceConfig.setSeizeProduce(rs.getInt("seizeProduce"));
                map.put(xiuXianPvpPlaceConfig.getId(), xiuXianPvpPlaceConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianTripodConfigSql = "select * from `t_s_activity_xiuxian_tripod` where `activityId`=?";
    public Map<Integer, XiuXianTripodConfig> getXiuXianTripodConfigMap(int activityId) {
        Map<Integer, XiuXianTripodConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianTripodConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianTripodConfig xiuXianTripodConfig = new XiuXianTripodConfig();
                xiuXianTripodConfig.setActivityId(rs.getInt("activityId"));
                xiuXianTripodConfig.setLevel(rs.getInt("level"));
                xiuXianTripodConfig.setNeedItem(rs.getString("needItem"));
                xiuXianTripodConfig.setStateLimit(rs.getInt("stateLimit"));
                xiuXianTripodConfig.setExtractConsume(rs.getInt("extractConsume"));
                xiuXianTripodConfig.setQualityWeight(rs.getString("qualityWeight"));
                xiuXianTripodConfig.setTypeRandom(rs.getString("typeRandom"));
                xiuXianTripodConfig.setLevelRandom(rs.getString("levelRandom"));
                xiuXianTripodConfig.setAdvancedLevelRandom(rs.getString("advancedLevelRandom"));
                xiuXianTripodConfig.setSkillLevelRandom(rs.getString("skillLevelRandom"));
                map.put(xiuXianTripodConfig.getLevel(), xiuXianTripodConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianEquipmentConfigSql = "select * from `t_s_activity_xiuxian_equipment` where `activityId`=?";
    public Map<Integer, XiuXianEquipmentConfig> getXiuXianEquipmentConfigMap(int activityId) {
        Map<Integer, XiuXianEquipmentConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianEquipmentConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianEquipmentConfig xiuXianEquipmentConfig = new XiuXianEquipmentConfig();
                xiuXianEquipmentConfig.setActivityId(rs.getInt("activityId"));
                xiuXianEquipmentConfig.setId(rs.getInt("id"));
                xiuXianEquipmentConfig.setIcon(rs.getInt("icon"));
                xiuXianEquipmentConfig.setType(rs.getInt("type"));
                xiuXianEquipmentConfig.setQuality(rs.getInt("quality"));
                xiuXianEquipmentConfig.setName(rs.getString("name"));
                xiuXianEquipmentConfig.setDesc(rs.getString("desc"));
                xiuXianEquipmentConfig.setAttribute(rs.getString("attribute"));
                xiuXianEquipmentConfig.setAdvancedAttribute(rs.getString("advancedAttribute"));
                xiuXianEquipmentConfig.setSkillType(rs.getInt("skillType"));
                xiuXianEquipmentConfig.setSkillParameter(rs.getString("skillParameter"));
                xiuXianEquipmentConfig.setRecoveryReward(rs.getString("recoveryReward"));
                map.put(xiuXianEquipmentConfig.getId(), xiuXianEquipmentConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianNpcConfigSql = "select * from `t_s_activity_xiuxian_npc` where `activityId`=?";
    public Map<Integer, XiuXianNpcConfig> getXiuXianNpcConfigMap(int activityId) {
        Map<Integer, XiuXianNpcConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianNpcConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianNpcConfig xiuXianNpcConfig = new XiuXianNpcConfig();
                xiuXianNpcConfig.setActivityId(rs.getInt("activityId"));
                xiuXianNpcConfig.setId(rs.getInt("id"));
                xiuXianNpcConfig.setIcon(rs.getInt("icon"));
                xiuXianNpcConfig.setType(rs.getInt("type"));
                xiuXianNpcConfig.setSmallType(rs.getInt("smallType"));
                xiuXianNpcConfig.setAttributeType(rs.getInt("attributeType"));
                xiuXianNpcConfig.setName(rs.getString("name"));
                xiuXianNpcConfig.setDesc(rs.getString("desc"));
                xiuXianNpcConfig.setAttribute(rs.getString("attribute"));
                xiuXianNpcConfig.setAdvancedAttribute(rs.getString("advancedAttribute"));
                map.put(xiuXianNpcConfig.getId(), xiuXianNpcConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianEventConfigSql = "select * from `t_s_activity_xiuxian_event` where `activityId`=?";
    public Map<Integer, XiuXianEventConfig> getXiuXianEventConfigMap(int activityId) {
        Map<Integer, XiuXianEventConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianEventConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianEventConfig xiuXianEventConfig = new XiuXianEventConfig();
                xiuXianEventConfig.setActivityId(rs.getInt("activityId"));
                xiuXianEventConfig.setId(rs.getInt("id"));
                xiuXianEventConfig.setType(rs.getInt("type"));
                xiuXianEventConfig.setEventParameter(rs.getString("eventParameter"));
                xiuXianEventConfig.setName(rs.getString("name"));
                xiuXianEventConfig.setIntroduce(rs.getString("introduce"));
                xiuXianEventConfig.setDesc(rs.getString("desc"));
                xiuXianEventConfig.setRewards(rs.getString("rewards"));
                xiuXianEventConfig.setFailRewards(rs.getString("failRewards"));
                xiuXianEventConfig.setIcon(rs.getInt("icon"));
                xiuXianEventConfig.setXianLi(rs.getLong("xianLi"));
                map.put(xiuXianEventConfig.getId(), xiuXianEventConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianMissionConfigSql = "select * from `t_s_activity_xiuxian_mission` where `activityId`=?";
    public Map<Integer, XiuXianMissionConfig> getXiuXianMissionMap(int activityId) {
        Map<Integer, XiuXianMissionConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianMissionConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianMissionConfig xiuXianMissionConfig = new XiuXianMissionConfig();
                xiuXianMissionConfig.setActivityId(rs.getInt("activityId"));
                xiuXianMissionConfig.setId(rs.getInt("id"));
                xiuXianMissionConfig.setType(rs.getInt("type"));
                xiuXianMissionConfig.setFloor(rs.getInt("floor"));
                xiuXianMissionConfig.setIcon(rs.getInt("icon"));
                xiuXianMissionConfig.setName(rs.getString("name"));
                xiuXianMissionConfig.setDesc(rs.getString("desc"));
                xiuXianMissionConfig.setStateLimit(rs.getInt("stateLimit"));
                xiuXianMissionConfig.setTerrain(rs.getString("terrain"));
                xiuXianMissionConfig.setSubsectionRewards(rs.getString("subsectionRewards"));
                xiuXianMissionConfig.setBuff(rs.getString("buff"));
                map.put(xiuXianMissionConfig.getId(), xiuXianMissionConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianStateConfigSql = "select * from `t_s_activity_xiuxian_state` where `activityId`=?";
    public Map<Integer, XiuXianStateConfig> getXiuXianStateConfigMap(int activityId) {
        Map<Integer, XiuXianStateConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianStateConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianStateConfig xiuXianStateConfig = new XiuXianStateConfig();
                xiuXianStateConfig.setActivityId(rs.getInt("activityId"));
                xiuXianStateConfig.setId(rs.getInt("id"));
                xiuXianStateConfig.setStateType(rs.getInt("stateType"));
                xiuXianStateConfig.setClassId(rs.getInt("classId"));
                xiuXianStateConfig.setMaxEffect(rs.getInt("maxEffect"));
                xiuXianStateConfig.setName(rs.getString("name"));
                xiuXianStateConfig.setNeedItem(rs.getString("needItem"));
                xiuXianStateConfig.setConsumeItem(rs.getString("consumeItem"));
                xiuXianStateConfig.setNeedXianLi(rs.getString("needXianLi"));
                xiuXianStateConfig.setMinXianLi(rs.getString("minXianLi"));
                xiuXianStateConfig.setPracticeSpeed(rs.getInt("practiceSpeed"));
                xiuXianStateConfig.setAttributeAdd(rs.getInt("attributeAdd"));
                map.put(xiuXianStateConfig.getId(), xiuXianStateConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getXiuXianUpgradeConfigSql = "select * from `t_s_activity_xiuxian_upgrade` where `activityId`=?";
    public Map<Integer, Map<Integer, XiuXianUpgradeConfig>> getXiuXianUpgradeConfigMap(int activityId) {
        Map<Integer, Map<Integer, XiuXianUpgradeConfig>> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianUpgradeConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianUpgradeConfig xiuXianUpgradeConfig = new XiuXianUpgradeConfig();
                xiuXianUpgradeConfig.setActivityId(rs.getInt("activityId"));
                xiuXianUpgradeConfig.setId(rs.getInt("id"));
                xiuXianUpgradeConfig.setType(rs.getInt("type"));
                xiuXianUpgradeConfig.setLevel(rs.getInt("level"));
                xiuXianUpgradeConfig.setUpgradeAtt(rs.getString("upgradeAtt"));
                if (!map.containsKey(xiuXianUpgradeConfig.getType())) {
                    map.put(xiuXianUpgradeConfig.getType(), new ConcurrentHashMap<>());
                }
                map.get(xiuXianUpgradeConfig.getType()).put(xiuXianUpgradeConfig.getLevel(), xiuXianUpgradeConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
    private static String getXiuXianPeakConfigSql = "select * from `t_s_activity_xiuxian_peak` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, XiuXianPeakConfig> getXiuXianPeakConfigMap(int activityId) {
        Map<Integer, XiuXianPeakConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiuXianPeakConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiuXianPeakConfig xiuXianPeakConfig = new XiuXianPeakConfig();
                xiuXianPeakConfig.setActivityId(rs.getInt("activityId"));
                xiuXianPeakConfig.setId(rs.getInt("id"));
                xiuXianPeakConfig.setName(rs.getString("name"));
                xiuXianPeakConfig.setIcon(rs.getInt("icon"));
                xiuXianPeakConfig.setDesc(rs.getString("desc"));
                xiuXianPeakConfig.setRoomNum(rs.getInt("roomNum"));
                xiuXianPeakConfig.setPeopleNum(rs.getInt("peopleNum"));
                xiuXianPeakConfig.setAttributeAdd(rs.getInt("attributeAdd"));
                map.put(xiuXianPeakConfig.getId(), xiuXianPeakConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
